package edu.tsinghua.oxy.common.entity;


import edu.tsinghua.oxy.common.constant.CodeConstants;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 交互返回实体
 * @author sean
 */
@Data
public class Result<T> {

	/**
	 * 状态码
	 */
	private String code;
	/**
	 * 描述信息
	 */
	private String msg;
	/**
	 * 返回数据
	 */
	private T date;
	/**
	 * 生成时间
	 */
	private LocalDateTime now = LocalDateTime.now();

	private Result(String c, String m, T d){
		this.code=c;
		this.msg=m;
		this.date=d;
	}

	private Result(String c, String m){
		this.code=c;
		this.msg=m;
	}

	private Result(String c, T d){
		this.code=c;
		this.date=d;
	}

	private Result(String c){
		this.code=c;
	}

	/** 返回 */

	public static<T> Result<T> success(){
		return new Result<>(CodeConstants.SUCCESS);
	}

	public static<T> Result<T> success(String m){
		return new Result<>(CodeConstants.SUCCESS, m);
	}

	public static<T> Result<T> success(T d){
		return new Result<T>(CodeConstants.SUCCESS, d);
	}

	public static<T> Result<T> success(String m, T d){
		return new Result<T>(CodeConstants.SUCCESS, m, d);
	}


	/** 返回 */

	public static<T> Result<T> back(String c, String m){
		return new Result<>(c, m);
	}

	public static<T> Result<T> back(String c, T d){
		return new Result<T>(c, d);
	}

	public static<T> Result<T> back(String c, String m, T d){
		return new Result<T>(c, m , d);
	}
	
}
